package com.bw.module_device.view

import androidx.lifecycle.ViewModelProvider
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.bw.lib_base.path.RouterPath
import com.bw.lib_common.view.BaseMvvmActivity
import com.bw.module_device.R
import com.bw.module_device.databinding.ActivityDeviceDetailBinding
import com.bw.module_device.viewmodel.DeviceViewModel
import com.github.gzuliyujiang.wheelpicker.OptionPicker
import java.text.SimpleDateFormat
/**
 * 智慧园区-01-设备管理-v1.1-吴熙-20250508
 */
@Route(path = RouterPath.PATH_DETAIL_DEVICE_ACTIVITY)
class DeviceDetailActivity : BaseMvvmActivity<ActivityDeviceDetailBinding>() {

    @Autowired
    @JvmField
    var deviceId=0

    private val viewModel by lazy { ViewModelProvider(this)[DeviceViewModel::class.java] }


    override fun initView() {
        ARouter.getInstance().inject(this)

        //头布局
        mDataBinding.goBack.setOnClickListener { finish() }
        mDataBinding.title.text="设备巡检任务详情"

        viewModel.getDeviceDetail(deviceId)

        mDataBinding.tvTime.text=SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis())

        //跳转到新增设备工单
        mDataBinding.goAdd.setOnClickListener {
            ARouter.getInstance().build(RouterPath.PATH_ADD_DEVICE_ACTIVITY).navigation()
        }

        //点击开始巡检
        mDataBinding.btnStartInsepection.setOnClickListener {
            ToastUtils.showLong("您已开始巡检")
            finish()
        }

        //点击转派按钮可选择相对应的负责人
        mDataBinding.btnTurnInsepection.setOnClickListener {
            val list= mutableListOf<String>()
            list.add("张三")
            list.add("李四")
            list.add("王五")
            list.add("赵六")
            val optionPicker = OptionPicker(this)
            optionPicker.setTitle("请选择负责人")
            optionPicker.setData(list)
            optionPicker.setDefaultPosition(0)//设置默认选中
            optionPicker.setOnOptionPickedListener { position, item ->
                ToastUtils.showLong("任务已转派给${list[position]}")
            }
            optionPicker.show()
        }
    }


    override fun observeDataChange() {
        viewModel.getDeviceDetailSuccess.observe(this){
            mDataBinding.tvProjectName.text=it.deviceName
        }
    }

    override fun getLayoutId(): Int =R.layout.activity_device_detail

}